package com.baobao.web;

import com.baobao.dao.BbeventDAO;

import com.baobao.domain.Bbevent;

import com.baobao.service.BbeventService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.servlet.ModelAndView;

/**
 * Spring MVC controller that handles CRUD requests for Bbevent entities
 * 
 */

@Controller("BbeventController")
public class BbeventController {

	/**
	 * DAO injected by Spring that manages Bbevent entities
	 * 
	 */
	@Autowired
	private BbeventDAO bbeventDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for Bbevent entities
	 * 
	 */
	@Autowired
	private BbeventService bbeventService;

	/**
	 * Register custom, context-specific property editors
	 * 
	 */
	@InitBinder
	public void initBinder(WebDataBinder binder, HttpServletRequest request) { // Register static property editors.
		binder.registerCustomEditor(java.util.Calendar.class, new org.skyway.spring.util.databinding.CustomCalendarEditor());
		binder.registerCustomEditor(byte[].class, new org.springframework.web.multipart.support.ByteArrayMultipartFileEditor());
		binder.registerCustomEditor(boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(false));
		binder.registerCustomEditor(Boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(true));
		binder.registerCustomEditor(java.math.BigDecimal.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(java.math.BigDecimal.class, true));
		binder.registerCustomEditor(Integer.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Integer.class, true));
		binder.registerCustomEditor(java.util.Date.class, new org.skyway.spring.util.databinding.CustomDateEditor());
		binder.registerCustomEditor(String.class, new org.skyway.spring.util.databinding.StringEditor());
		binder.registerCustomEditor(Long.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Long.class, true));
		binder.registerCustomEditor(Double.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Double.class, true));
	}

	/**
	 * Select an existing Bbevent entity
	 * 
	 */
	@RequestMapping("/selectBbevent")
	public ModelAndView selectBbevent(@RequestParam String bbIdKey, @RequestParam String timeKey) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("bbevent", bbeventDAO.findBbeventByPrimaryKey(bbIdKey, timeKey));
		mav.setViewName("bbevent/viewBbevent.jsp");

		return mav;
	}

	/**
	 * Edit an existing Bbevent entity
	 * 
	 */
	@RequestMapping("/editBbevent")
	public ModelAndView editBbevent(@RequestParam String bbIdKey, @RequestParam String timeKey) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("bbevent", bbeventDAO.findBbeventByPrimaryKey(bbIdKey, timeKey));
		mav.setViewName("bbevent/editBbevent.jsp");

		return mav;
	}

	/**
	 */
	@RequestMapping("/bbeventController/binary.action")
	public ModelAndView streamBinary(@ModelAttribute HttpServletRequest request, @ModelAttribute HttpServletResponse response) {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("streamedBinaryContentView");
		return mav;

	}

	/**
	 * Select the Bbevent entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@RequestMapping("/confirmDeleteBbevent")
	public ModelAndView confirmDeleteBbevent(@RequestParam String bbIdKey, @RequestParam String timeKey) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("bbevent", bbeventDAO.findBbeventByPrimaryKey(bbIdKey, timeKey));
		mav.setViewName("bbevent/deleteBbevent.jsp");

		return mav;
	}

	/**
	 * Entry point to show all Bbevent entities
	 * 
	 */
	public String indexBbevent() {
		return "redirect:/indexBbevent";
	}

	/**
	 * Create a new Bbevent entity
	 * 
	 */
	@RequestMapping("/newBbevent")
	public ModelAndView newBbevent() {
		ModelAndView mav = new ModelAndView();

		mav.addObject("bbevent", new Bbevent());
		mav.addObject("newFlag", true);
		mav.setViewName("bbevent/editBbevent.jsp");

		return mav;
	}

	/**
	 * Save an existing Bbevent entity
	 * 
	 */
	@RequestMapping("/saveBbevent")
	public String saveBbevent(@ModelAttribute Bbevent bbevent) {
		bbeventService.saveBbevent(bbevent);
		return "forward:/indexBbevent";
	}

	/**
	 * Delete an existing Bbevent entity
	 * 
	 */
	@RequestMapping("/deleteBbevent")
	public String deleteBbevent(@RequestParam String bbIdKey, @RequestParam String timeKey) {
		Bbevent bbevent = bbeventDAO.findBbeventByPrimaryKey(bbIdKey, timeKey);
		bbeventService.deleteBbevent(bbevent);
		return "forward:/indexBbevent";
	}

	/**
	 * Show all Bbevent entities
	 * 
	 */
	@RequestMapping("/indexBbevent")
	public ModelAndView listBbevents() {
		ModelAndView mav = new ModelAndView();

		mav.addObject("bbevents", bbeventService.loadBbevents());

		mav.setViewName("bbevent/listBbevents.jsp");

		return mav;
	}
}